<template>
  <div class="playlist">
    <div class="head">
      <div class="head-img" :style="{ 'background-image': 'url(' + this.playlist.coverImgUrl + ')' }"></div>
      <div class="head-list">
        <div class="head-portrait">
          <img :src="this.playlist.coverImgUrl" alt="">
          <span>歌单</span>
          <i v-if="this.playlist.playCount">{{this.playlist.playCount|formatNumber}}</i>
        </div>
        
      </div>
    </div>
    <ListTitle>歌曲列表</ListTitle>
    <SongList :shownumber="true" @play="$emit('play',$event)" :songlist="showSong"></SongList>
    <div v-show="showSong.length>0" class="more" ref="more" @click="loadMore">{{page>=10?"没有更多了":"点击加载更多"}}</div>
    <ListTitle>歌曲评论</ListTitle>
    <Comment :item="comments"></Comment>
  </div>
</template>

<script>
import ListTitle from '@/components/ListTitle.vue'
import SongList from '@/components/SongList.vue'
import Comment from '@/components/Comment.vue'
export default {
  components: {ListTitle,SongList,Comment},
  props: ["pid"],
  data() {
    return {
      playlist: [],
      musicsong:[],
      comments:[],
      page:1
    };
  },
  filters:{
        formatNumber(value){
            return (value/10000).toFixed(1)+"万";
        }
    },
  created() {
    this.getPlayList();
    this.getComment();
    this.getMusic()
  },
  beforeRouteEnter(to, from, next) {
    next();
  },
  methods: {
    //异步代码 同步的写法
    async getPlayList() {
      let re = await this.axios.get("/playlist/detail?id=" + this.pid);
      this.playlist = re.playlist;
      console.log("歌单详情", this.playlist);
    },
    async getComment() {
      let re = await this.axios.get("/comment/playlist?id=" + this.pid);
      this.comments = re.comments
      console.log("歌单评论==>", this.comments);
    },
    async getMusic(){
      let re = await this.axios.get("/playlist/track/all?id=" + this.pid)
      let musicsong = re.songs;
      this.musicsong = musicsong.map((song,index)=>{
        song.song = {
          album: song.al,
          privilege: re.privileges[index],
          artists: song.ar,
          alias: song.alia,
        };
        return song
      })
      console.log("列表",re)
    },
    // 分页
    loadMore(){
      if(this.page>=10){
        alert("没有更多了");
        return;
      }
      this.page++;//下一页
    },
  },
  computed:{
    showSong(){
      return this.musicsong.slice(0,20*this.page);
    }
  },
};
</script>

<style lang="less" scoped>
.playlist {
  .head {
    width: 100%;
    height: 150px;
    box-sizing: border-box;
    border: 1px solid black;
    position: relative;
    display: flex;
    align-items: center;
    .head-img{
      position: absolute;
      left: 0px;
      top: 0px;
      width: 100%;
      height: 100%;
      background-position: 50%;
      background-repeat: no-repeat;
      background-size: 100% 100%;
      filter: blur(3.9px) 
    }
    .head-list{
      width: 100%;
      height: 130px;
      z-index: 1;
      .head-portrait{
        width: 130px;
        height: 130px;
        margin-left: 20px;
        border-radius: 10px;
        box-sizing: border-box;
        border: 1px solid black;
        position: relative;
        &>img{
          width: 100%;
          height: 100%;
          position: absolute;
          background-repeat: no-repeat;
          background-size: 130px 130px;
          border-radius: 10px;
        }
        &>span{
          position: absolute;
          top: 10px;
          width: 40px;
          height: 20px;
          text-align: center;
          line-height: 20px;
          background: red;
          color: white;
          font-size: 14px;
          border-radius: 0px 6px 6px 0px;
        }
        &>i{
          position: absolute;
          top: 10px;
          right: 0px;
          color: white;
          font-size: 12px;
        }
      }
    }
  }
  .more{
    text-align: center;
    line-height: 40px;
    font-size:13px;
    color:#666;
  }
}
</style>